package com.bw.controller;

import com.bw.entity.Dict;
import com.bw.entity.MaterialsInfo;
import com.bw.entity.MaterialsQuery;
import com.bw.mapper.MaterialsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class ListController {

    @Autowired
    MaterialsMapper materialsMapper;

    @RequestMapping("/list.do")
    public String list(MaterialsQuery query, @RequestParam(defaultValue = "1") Integer pageNum, Model model){
        //1. 查询下拉框
        List<Dict> typeList = materialsMapper.listType();
        model.addAttribute("typeList",typeList);
        //2.分页查询
        PageHelper.startPage(pageNum,10);
        List<MaterialsInfo> list = materialsMapper.selectByParam(query);
        PageInfo<MaterialsInfo> pageInfo = new PageInfo<>(list);
        model.addAttribute("pageInfo",pageInfo);
        //3. 条件回显
        model.addAttribute("query",query);
        return "list";
    }
}
